/***************************************************************************
                          parser.h  -  description
                             -------------------
    begin                : Mon May 6 2002
    copyright            : (C) 2002 by Michiel Visser
    email                :
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/

#ifndef PARSER_H
#define PARSER_H

#include "expr.h"

using namespace Expression;

class TyleParser
{
public:
  TyleParser(unsigned char *pos, EPtr &result, void *returnObjectSpace);
	static unsigned char *parseInt(unsigned char *p, int &base, /*out*/ int &result); // returns zero if no integer parsed. result is zero.
private:
  short    m_c;
  int      m_line;
  unsigned char *   m_pos; 
  int m_strlen;
	int m_dynamic;
  String   m_s;
	struct
	{	List<TypeFunc>::P funcs;
	} structing;
	void addStructElem(List<StructElem> &ses, TypePtr parent, String name, TypePtr type, TypeFunc *func);
	void structing_storeTxt(const char *s);
  void storeChar(int &pos) { m_s[pos++]=(unsigned char)m_c; }
  void nextRawChar()
  {	m_c=*(m_pos++);
  	if (m_c==10) m_line++;
  }
  void nextChar();
  void skipSpaces()
  {  while (m_c>0 && m_c<=' ') nextChar();
  }
  void nextWord();
  bool parseWord(char *word);
	static int parseDigits(unsigned char *p, int &result, int base=10);
  void pcheck(EPtr o) { if (!o) throw("Missing Operand."); }
	EPtr finishParseList();
	EPtr finishParseSequence();
	EPtr finishMap();
	TypePtr parseType       (/*out*/ TypeFunc *&funcOut);
	TypePtr parseTypeMapping(/*out*/ TypeFunc *&funcOut);
	TypePtr parseTypeLeftVal(/*out*/ TypeFunc *&funcOut);
  TypePtr parseTypeLiteral  (/*out*/ TypeFunc *&funcOut);
	TypePtr parseTypeAssignment(/*out*/ TypeFunc *&funcOut);
	TypePtr parseTypeSelection(/*out*/ TypeFunc *&funcOut);
	TypePtr parseStructConcat (/*out*/ TypeFunc *&funcOut);
  EPtr parseBinary(int level=100);
  EPtr parseBinaryOp(EPtr cur, int level);
#define DEF_PARSEFUNC
#define P(x,l) EPtr parse##x();
	#include"parseunits.h"
#undef P
#undef DEF_PARSEFUNC
#define parseExpr parseAssign
  EPtr parseSequence();
  EPtr parseTypeSelectionExpr();
};

#endif // FILEXXX_H

